package com.jhrc.portal.ws.message;

import com.jhrc.portal.ws.utils.GZIPUtil;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author luanxd
 * @date 2020-05-18
 */
public class DefaultReceiveMessage implements ReceiveMessage {
    private Logger logger = LoggerFactory.getLogger(DefaultReceiveMessage.class);

    @Override
    public void onMessage(Channel channel, String text) {
        System.err.println(text);
        //LogUtils.console_print("message: " + text);
    }

    @Override
    public void onMessage(Channel channel, byte[] bytes) {
        try{
            String t = new String(GZIPUtil.uncompress(bytes), "Utf-8");
            logger.info("message: " + t);
        }catch (Exception e){
            e.printStackTrace();
            logger.info("Fail to process byte message");
        }

    }

    @Override
    public void onMessage(Channel channel, WebSocketFrame frame) {
        logger.info("message: " + frame.toString());
    }
}
